package com.wshl.aijiuunion.view.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.wshl.aijiuunion.GlobConstant;
import com.wshl.aijiuunion.NetUrl;
import com.wshl.aijiuunion.R;
import com.wshl.aijiuunion.controller.activity.VideoDetailActivity;
import com.wshl.aijiuunion.utils.GlideUtils;
import com.wshl.aijiuunion.view.bean.VideoListBean;
import com.wshl.aijiuunion.view.bean.VideoRecordBean;
import com.wshl.aijiuunion.view.widget.RoundCornerImageView;

import java.util.List;

import cn.bingoogolapple.baseadapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.baseadapter.BGAViewHolderHelper;

public class VideoRecordAdapter extends BGARecyclerViewAdapter<VideoRecordBean.DataBeanX.DataBean> {
    public VideoRecordAdapter(RecyclerView recyclerView) {
        super(recyclerView, R.layout.item_video);
    }

    @Override
    protected void fillData(BGAViewHolderHelper helper, int position, VideoRecordBean.DataBeanX.DataBean model) {

        VideoRecordBean.DataBeanX.DataBean.VideoBean video = model.getVideo();
        String cover = video.getCover();
        int hits = video.getHits();
        String title = video.getTitle();
        List<String> types = video.getType();
        String type_name = video.getType_name();

        helper.setText(R.id.tv_video_title, title);
        helper.setText(R.id.tv_video_count, hits + "人已学习");
        helper.setText(R.id.tv_video_shenfen, type_name + "可以观看");
        RoundCornerImageView imageView = (RoundCornerImageView) helper.getImageView(R.id.item_img_video);
        GlideUtils.loadImage(mContext, NetUrl.IMG + cover, imageView);

        helper.getView(R.id.rl_video_item).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String type = SPUtils.getInstance().getString(GlobConstant.TYPE, "0");
                if (!type_name.equals("全部") && !types.contains(type)) {
                    ToastUtils.showLong("您当前身份不能学习此课程");
                    return;
                }
                Intent intent = new Intent(mContext, VideoDetailActivity.class);
                intent.putExtra(GlobConstant.VIDEOID, model.getVideo_id());
                ActivityUtils.startActivity(intent);

            }
        });
    }
}
